/**
 * =============================================================================
 * ************   Checkbox 复选框   ************
 * =============================================================================
 */

.mdui-checkbox {
  display: inline-block;
  position: relative;
  padding-left: 36px;
  height: 36px;
  line-height: 36px;
  cursor: pointer;
  user-select: none;

  // 隐藏系统 input 标签，用自定义的图标代替
  input {
    height: 0;
    width: 0;
    overflow: hidden;
    position: absolute;
    visibility: hidden;
  }
}

/* 透明的圆形，用于生成圆形阴影 */
.mdui-checkbox-icon {
  position: absolute;
  left: 0;
  top: 9px;
  display: inline-block;
  vertical-align: middle;
  width: 18px;
  height: 18px;
  border-radius: 18px;
  background-color: transparent;
  border: none;
  transition: box-shadow .14s @animation-curve-default;

  // 图标的边框和背景
  &:after {
    content: ' ';
    box-sizing: border-box;
    position: absolute;
    top: 0;
    left: 0;
    width: 18px;
    height: 18px;
    border: 2px solid @color-black-icon;
    border-radius: 2px;
    transition: all .3s @animation-curve-default;
    z-index: 0;
  }

  // 图标内部的勾
  &:before {
    content: ' ';
    box-sizing: border-box;
    position: absolute;
    top: 2px;
    left: 0;
    width: 8px;
    height: 13px;
    transform: rotateZ(37deg) scale(0);
    transform-origin: 100% 100%;
    border-right: 2px solid #fff;
    border-bottom: 2px solid #fff;
    transition: all .3s @animation-curve-default;
    opacity: 0;
    z-index: 1;
  }
}

/* 选中状态的图标 */
.mdui-checkbox input[type="checkbox"]:checked + .mdui-checkbox-icon {
  &:after {
    border-color: @color-default-a200;
    background-color: @color-default-a200;
  }

  &:before {
    opacity: 1;
    transform: rotateZ(37deg) scale(1);
  }
}

/* 禁用状态的图标 */
.mdui-checkbox input[type="checkbox"]:disabled + .mdui-checkbox-icon {
  &:after {
    border-color: @color-black-icon-disabled;
  }
}

/* 禁用且选中状态 */
.mdui-checkbox input[type="checkbox"]:disabled:checked + .mdui-checkbox-icon {
  &:after {
    background-color: @color-black-icon-disabled !important;
    border-color: transparent !important;
  }
}

/* 未选中、禁用时 按下的阴影 */
.mdui-checkbox:active input[type="checkbox"] +.mdui-checkbox-icon {
  box-shadow: 0 0 0 15px rgba(0, 0, 0, 0.1);
}

/* 已选中时按下的阴影 */
.mdui-checkbox:active input[type="checkbox"]:checked:not(:disabled) + .mdui-checkbox-icon {
  box-shadow: 0 0 0 15px rgba(red(@color-default-a200), green(@color-default-a200), blue(@color-default-a200), 0.16);
}


/**
 * =============================================================================
 * ************   Checkbox 强调色   ************
 * =============================================================================
 */

& {
  .loop-accent-theme(@counter-color) when (@counter-color > 0) {
    .loop-accent-theme((@counter-color - 1));
    @colorName: extract(@globalAccentColors, @counter-color);

    @color: 'color-@{colorName}-a200';

    .mdui-theme-accent-@{colorName} {

      // 选中状态的图标
      .mdui-checkbox input[type="checkbox"]:checked + .mdui-checkbox-icon {
        &:after {
          border-color: @@color;
          background-color: @@color;
        }
      }

      // 已选中时按下的阴影
      .mdui-checkbox:active input[type="checkbox"]:checked:not(:disabled) + .mdui-checkbox-icon {
        box-shadow: 0 0 0 15px rgba(red(@@color), green(@@color), blue(@@color), 0.16);
      }

    }
  }
  .loop-accent-theme(length(@globalAccentColors));
}


/**
 * =============================================================================
 * ************   Checkbox dark   ************
 * =============================================================================
 */

.mdui-theme-layout-dark when (@globalLayoutDark = true) {

  // 未选中的图标
  .mdui-checkbox-icon {
    &:after {
      border-color: rgba(255, 255, 255, 0.7);
    }
    &:before {
      border-right-color: @layout-dark-color-3;
      border-bottom-color: @layout-dark-color-3;
    }
  }

  // 禁用状态
  .mdui-checkbox input[type="checkbox"]:disabled + .mdui-checkbox-icon {
    &:after {
      border-color: @color-white-icon-disabled;
    }
  }

  // 禁用且选中状态
  .mdui-checkbox input[type="checkbox"]:disabled:checked + .mdui-checkbox-icon {
    &:after {
      background-color: @color-white-icon-disabled !important;
      border-color: transparent !important;
    }
  }

  // 未选中或禁用时 按下的阴影
  .mdui-checkbox:active input[type="checkbox"] + .mdui-checkbox-icon {
    box-shadow: 0 0 0 15px rgba(255, 255, 255, 0.1);
  }
}
